package com.yuji.aacar.controller.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yuji.aacar.R;
import com.yuji.aacar.bean.beans.PushMessage;

import java.util.ArrayList;


public class MessageAdapter extends BaseAdapter {


    private Context context;
    private ArrayList<PushMessage> list;

    public MessageAdapter(Context context, ArrayList<PushMessage > list){
        this.context=context;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list == null ? 0:list.size();
    }
    @Override
    public Object getItem(int position) {
        return list.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.activity_message_item,null);
            viewHolder=new ViewHolder();
            viewHolder.title= (TextView) convertView.findViewById(R.id.message_title);
            viewHolder.time= (TextView) convertView.findViewById(R.id.message_time);
            viewHolder.content= (TextView) convertView.findViewById(R.id.message_content);
            convertView.setTag(viewHolder);
        } else {
            viewHolder= (ViewHolder) convertView.getTag();
        }

        viewHolder.time.setText(list.get(position).getTime());
        viewHolder.title.setText(list.get(position).getTitle());
        viewHolder.content.setText(list.get(position).getCustom());
        return convertView;
    }
    public static  class ViewHolder{
        TextView title;
        TextView time;
        TextView content;
    }
}
